package com.alks.common.utils.export.service.impl;

import com.alks.common.utils.export.dto.FileInfoDTO;
import com.alks.common.utils.export.dto.MockMultipartFile;
import com.alks.common.utils.export.service.ExportCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

/**
 * @author: chen
 * @date: 2024/12/27
 * @description:
 */
@Slf4j
public class DefaultExportCallbackImpl implements ExportCallback {

    @Override
    public void onProgressUpdate(double progress) {
        log.debug("文件更新进度 {}%", progress * 100);
    }

    @Override
    public void onFileGenerated(MockMultipartFile file) {
        log.debug("导出文件生成成功: {}", file.getOriginalFilename());
        onProgressUpdate(0.5);
    }

    @Override
    public void onError(Throwable e) {
        if (e instanceof NoSuchBeanDefinitionException) {
            log.error("未定义实现类 {}", e.getMessage());
        } else {
            log.error("文件导出发生异常" + e.getMessage());
        }
    }

    @Override
    public void onComplete(FileInfoDTO fileInfo) {
        log.debug("文件【{}】已生成并上传", fileInfo.getOriginal());
    }
}
